/*

This file is part of Ext JS 4

Copyright (c) 2011 Sencha Inc

Contact:  http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.

*/
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', 'static/ux');
Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.ux.grid.FiltersFeature',
    'Ext.toolbar.Paging'
]);

	Ext.define('Usuarios', {
		extend: 'Ext.data.Model',
		fields: [{
			name: 'id',
			type: 'int'
		},{
			name: 'first'
		}, {
			name: 'last'
		}, {
			name: 'email'
		}]
	});

Ext.onReady(function(){

    Ext.QuickTips.init();

    var store = Ext.create('Ext.data.JsonStore', {
        // store configs
        autoDestroy: true,
        model: 'Usuarios',
        proxy: {
            type: 'ajax',
            url: '/listar',
            reader: {
                type: 'json',
                root: 'data',
                idProperty: 'id',

            }
        },
        remoteSort: false,
        sorters: [{
            property: 'id',
            direction: 'ASC'
        }],
        pageSize: 50
    });


    
    // configure whether filtering is performed locally or remotely (initially)
    var local = true;


    var filters = {
        ftype: 'filters',
        local: local,   // defaults to false (remote filtering)


    };

    var grid = Ext.create('Ext.grid.Panel', {
        border: false,
        frame: true,
        store: store,
        columns:[{
            dataIndex: 'id',
            text: 'Id',
            // instead of specifying filter config just specify filterable=true
            // to use store's field's type property (if type property not
            // explicitly specified in store config it will be 'auto' which
            // GridFilters will assume to be 'StringFilter'
            filterable: true,
            width: 30
            //,filter: {type: 'numeric'}
        }, {
            dataIndex: 'first',
            text: 'first',
            id: 'first',
            flex: 1,
            filter: {
                type: 'string'
                // specify disabled to disable the filter menu
                //, disabled: true
            }
        }, {
            dataIndex: 'last',
            text: 'last',
            id: 'last',
            flex: 1,
            filter: {
                type: 'string'
                // specify disabled to disable the filter menu
                //, disabled: true
            }
        }, {
            dataIndex: 'email',
            text: 'E-mail',
            id: 'email',
          
            width: 180,
            filter: {
                type: 'string'
                // specify disabled to disable the filter menu
                //, disabled: true
            }
        }],
        loadMask: true,
        renderTo: 'filter-grid',
        width: 600,
        height: 400,
        features: [filters],
        dockedItems: [Ext.create('Ext.toolbar.Paging', {
            dock: 'bottom',
            store: store
        })]
    });



/*
    var win = Ext.create('Ext.Window', {
        title: 'Grid Filters Example',
        height: 400,
        width: 700,
        layout: 'fit',
        items: grid
    }).show();*/

    store.load();
});
